local jincu = fk.CreateSkill{
  name = "sclan__jincu",
  tags = { Skill.Switch },
  dynamic_desc = function (self, player, lang)
    local mark = player:getMark(self.name)
    local ret = "sclan__jincu_inner"
    local all_index = { "①", "②", "③", "④" }
    local all_des = { "射【杀】", "射【杀】", "射【杀】", "【一刀斩】" }
    for i = 1, 4 do
      local tail = all_index[i]
      if mark.all_names[i] == "" then
        tail = tail .. "<s>".. all_des[i] .. "</s>"
      else
        tail = tail .. all_des[i]
      end
      if i == mark.current then
        tail = "<font color=\"#E0DB2F\">" .. tail .. "</font>"
      end
      ret = ret .. ":" .. tail
    end
    return ret
  end,
}

Fk:loadTranslationTable{
  ["sclan__jincu"] = "劲簇",
  [":sclan__jincu"] = "转换技，你可以将一张基本牌当①射【杀】②射【杀】③射【杀】④【一刀斩】使用。",
  ["#sclan__jincu"] = "你可以将一张基本牌当%arg使用",

  [":sclan__jincu_inner"] = "转换技，你可以将一张基本牌当{1}{2}{3}{4}使用。"
}

jincu:addAcquireEffect(function (self, player, is_start)
  local mark = {
    all_names = { "shoot__slash", "shoot__slash", "shoot__slash", "execute" },
    current = 1,
  }
  player.room:setPlayerMark(player, jincu.name, mark)
end)

jincu:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, jincu.name, 0)
end)

---@param player ServerPlayer
local switchJincu = function (player)
  local mark = player:getMark(jincu.name)
  local current = mark.current
  while true do
    current = current + 1
    if current > 4 then current = current % 4 end
    if mark.all_names[current] ~= "" then
      break
    end
  end
  mark.current = current
  player.room:setPlayerMark(player, jincu.name, mark)
end

jincu:addEffect("viewas", {
  anim_type = "switch",
  prompt = function (self, player, selected_cards, selected)
    local mark = player:getMark(jincu.name)
    local all_des = { "射【杀】", "射【杀】", "射【杀】", "【一刀斩】" }
    return "#sclan__jincu:::" .. all_des[mark.current]
  end,
  handly_pile = true,
  pattern = "shoot__slash,execute",
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeBasic
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 then return end
    local mark = player:getMark(jincu.name)
    local card = Fk:cloneCard(mark.all_names[mark.current])
    card.skillName = jincu.name
    card:addSubcards(cards)
    return card
  end,
  enabled_at_play = function (self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end,
  before_use = function (self, player, use)
    switchJincu(player)
  end,
})

return jincu